package com.itheima.service.impl;

import com.itheima.service.MsgService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * ClassName: MsgServiceImpl
 * Description:
 * Date: 2023/03/09 PM 11:50:16
 * <p>
 * project: springboot
 * package: com.itheima.service.impl
 * email: 1085844536@qq.com
 * version:
 *
 * @author WangGuojian
 */
@Service
public class MsgServiceImpl implements MsgService {

    private final Map<String, String> cache = new HashMap<>();

    /**
     * 获取短信
     *
     * @param tele {@link String}
     * @return {@link String}
     */
    @Override
    public String get(String tele) {
        String code = tele.substring(tele.length() - 6);
        cache.put(tele, code);
        return code;
    }

    /**
     * 验证
     *
     * @param tele {@link String}
     * @param code {@link String}
     * @return {@link Boolean}
     */
    @Override
    public boolean check(String tele, String code) {
        String queryCode = cache.get(tele);
        return code.equals(queryCode);
    }
}
